import {
  postReportApi
} from "../../../https/dynamic"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: "",
    typeList: ["我不喜欢", "侵犯权益", "色情低俗", "违法犯罪", "政治敏感", "不实信息", "网络暴力", "其他"],
    type: "我不喜欢",
    targetId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if (!options.docid) {
      setTimeout(() => {
        wx.navigateBack()
      }, 500);
      wx.showToast({
        title: '动态id为加载',

      })
      return

    }
    this.setData({
      targetId: options.docid
    })

  },
  changeType(e) {
    console.log(e)
    const type = e.currentTarget.dataset.type
    this.setData({
      type
    })
  },
  changeInput(e) {
    console.log(e)
    const value = e.detail.value
    this.setData({
      value
    })
  },
  // 提交按钮
  async bindSubmit(e) {
    const content = this.data.value
    const targetId = this.data.targetId
    const type = this.data.type

    if (!content) {
      wx.showToast({
        title: '请输入举报内容',
        icon: 'none'
      })
      return
    }
    if (!type) {
      wx.showToast({
        title: '请选择举报类型',
        icon: 'none'
      })
      return
    }
    const postRes = await postReportApi({
      content,
      targetId,
      type
    })
    console.log(postRes)
    if (postRes.code == 200) {
      wx.showToast({
        title: '举报成功',
        icon: "success"
      })
      setTimeout(() => {
        wx.navigateBack()
      }, 500);
    } else {
      wx.showToast({
        title: '举报失败',
        icon: 'error'
      })
    }
  }
})